package com.ruoyi.oa.controller;

import java.util.List;

import com.ruoyi.oa.domain.OaFileUser;
import com.ruoyi.oa.service.IOaFileUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文档权限Controller
 * 
 * @author luguanqing
 * @date 2022-02-09
 */
@RestController
@RequestMapping("/oa/fileuser")
public class OaFileUserController extends BaseController
{
    @Autowired
    private IOaFileUserService oaFileUserService;

    /**
     * 查询文档权限列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OaFileUser oaFileUser)
    {
        startPage();
        List<OaFileUser> list = oaFileUserService.selectOaFileUserList(oaFileUser);
        return getDataTable(list);
    }

    /**
     * 导出文档权限列表
     */
    @Log(title = "文档权限", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OaFileUser oaFileUser)
    {
        List<OaFileUser> list = oaFileUserService.selectOaFileUserList(oaFileUser);
        ExcelUtil<OaFileUser> util = new ExcelUtil<OaFileUser>(OaFileUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 获取文档权限详细信息
     */
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") String fileId)
    {
        return AjaxResult.success(oaFileUserService.selectOaFileUserById(fileId));
    }

    /**
     * 新增文档权限
     */
    @Log(title = "文档权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaFileUser oaFileUser)
    {
        return toAjax(oaFileUserService.insertOaFileUser(oaFileUser));
    }

    /**
     * 修改文档权限
     */
    @Log(title = "文档权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaFileUser oaFileUser)
    {
        return toAjax(oaFileUserService.updateOaFileUser(oaFileUser));
    }

    /**
     * 删除文档权限
     */
    @Log(title = "文档权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable String[] fileIds)
    {
        return toAjax(oaFileUserService.deleteOaFileUserByIds(fileIds));
    }
}
